package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC799 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public double champagneTower(int poured, int query_row, int query_glass) {
            double[][] dp = new double[101][101];
            dp[0][0] = poured;
            for (int i = 1; i <= query_row; i++) {
                for (int j = 0; j <= i + 1; j++) {
                    dp[i][j] = (Math.max(dp[i - 1][j] - 1, 0)) / 2 + (j == 0 ? 0 : Math.max(dp[i - 1][j - 1] - 1, 0)) / 2;
                }
            }

            return Math.min(dp[query_row][query_glass], 1.0);
        }
    }

    public void run() {
        Solution solution = new Solution();
//        System.out.println(solution.champagneTower(4, 2, 2));
//        System.out.println(solution.champagneTower(100000009, 33, 17));
//        System.out.println(solution.champagneTower(1, 1, 17));
        System.out.println(solution.champagneTower(1000000000, 99, 99));
    }

    public static void main(String[] args) throws Exception {
        LC799 an = new LC799();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
